<template>
	<view class="container">
		<view class="banner">
			<image src="https://z3.ax1x.com/2021/09/17/4uR1IO.jpg" mode="" class="bg"></image>
			<view class="intro">
				<view class="greet">您好，{{ isLogin ? member.nickname : '游客' }}</view>
			</view>
		</view>
		<view class="content">
			<view class="entrance">
				<view class="item" @tap="takein">
					<image src="/static/images/index/yuyueguahao2.png" class="icon"></image>
					<view class="title">预约挂号</view>
				</view>
				<view class="item" @tap="takeup">
					<image src="/static/images/index/guahaowenzhen.png" class="icon"></image>
					<view class="title">当日挂号</view>
				</view>
				<view class="item" @tap="takeout">
					<image src="/static/images/index/jiaofeo.png" class="icon"></image>
					<view class="title">门诊缴费</view>
				</view>
			</view>
			<view class="info">
				<view class="integral_section" @tap="integrals">

					<view class="bottom" >
						<button type="default" v-show="!flag">添加就诊卡</button>
						<view  v-show="flag" style=" margin:20rpx 0rpx 0rpx 60rpx;">
							 <view style="font-size: 32rpx; color: #3ECEB6; font-weight: bold; margin-bottom:10rpx;">{{username}}</view>
							<view style="font-size: 26rpx; color: #3ECEB6;">{{userId}}</view>
						</view>
					</view>
					
				</view>
				<view class="qrcode_section" @tap="memberCode">
					<image src="../../static/images/index/check2.jpg"></image>
				</view>
			</view>
			
			<Tabs :TabList="TabList" :currentTab="current" @tabs="tabsChange">
				<TabPane>

					<!-- 分类列表 -->
					<view class="category-list">
						<view class="category" v-for="(row, index) in categoryList" :key="index" @tap="toCategory(row.url)">
							
							<view class="img">
								<image :src="row.img"></image>
							</view>
							<view class="text">{{ row.name }}</view>
						</view>
					</view>

				</TabPane>
				<TabPane>
					<view class="category-list">
						<view class="category" v-for="(row, index) in categoryList2" :key="index"
							@tap="toCategory(row.url)">
							<view class="img">
								<image :src="row.img"></image>
							</view>
							<view class="text">{{ row.name }}</view>
						</view>
					</view>

				</TabPane>

			</Tabs>
			<view class="member-news">
				<view class="header">
					<view class="title">科技改变生活</view>

				</view>
				<view class="list">
					<view class="item">
						<image src="https://s4.ax1x.com/2021/12/17/TF3sDP.jpg"></image>
						<view class="title">科技改变生活</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex'
	import TabPane from '../../components/wiszx-tabs/tabPane.vue'
	import Tabs from '../../components/wiszx-tabs/tabs.vue'
	import mm from '../../api/member.js'
	export default {
		data() {
			return {
				current: 0,
				TabList: [{
						title: '门诊'
					},
					{
						title: '住院'
					}

				],
				userId:0,
				username:'',
				flag:"",
				categoryList: [{
						id: 1,
						name: '添加就诊人',
						img: '/static/images/index/tianjiajiuzhenren.png',
						url:'../../pages/addjiuzhenren/addjiuzhenren'
						
					},
					{
						id: 2,
						name: '就诊卡充值',
						img: '/static/images/index/jiuzhenkachongzhi.png',
						url:'../../pages/address/address'
					},
					{
						id: 3,
						name: '缴费记录',
						img: '/static/images/index/jiaofeijilu.png',
						url:'../../pages/address/address'
					},
					{
						id: 4,
						name: '挂号记录',
						img: '/static/images/index/guahaojilu.png',
						url:'../../pages/appointment/guahaojilu'
					},
					{
						id: 5,
						name: '排队候诊',
						img: '/static/images/index/paiduijiuzhen.png',
						url:'../../pages/address/address'
					},
					{
						id: 6,
						name: '报告查询',
						img: '/static/images/index/baogaochaxun.png',
						url:'../../pages/address/address'
					},
					{
						id: 7,
						name: '电子发票',
						img: '/static/images/index/dianzifapiao.png',
						url:'../../pages/address/address'
					},
					// {
					// 	id: 8,
					// 	name: '',
					// 	img: ''
					// }
				],
				categoryList2: [{
						id: 1,
						name: '住院清单',
						img: '/static/images/index/zhuyuanqingdan.png',
						url:''
					},
					{
						id: 2,
						name: '住院缴费',
						img: '/static/images/index/zhuyuanjiaofei.png',
						url:''
					},
					{
						id: 3,
						name: '添加住院人',
						img: '/static/images/index/tianjiazhuyuanren.png',
						url:'../../pages/detailed/detailed'
					},
					{
						id: 4,
						name: '押金记录',
						img: '/static/images/index/yanjin.png',
						url:''
					},
					{
						id: 5,
						name: '病历复印',
						img: '/static/images/index/bingli.png',
						url:''
					},
					{
						id: 6,
						name: '报告查询',
						img: '/static/images/index/zhuyuanbaogao.png',
						url:''
					}
				],
				jiuzhenren:[],
			}
		},
		components: {
			Tabs,
			TabPane
		},
		computed: {
			...mapState(['member']),
			...mapGetters(['isLogin'])
		},
		// onLoad() {
		// 	this.getjiuzhenren()
		// },
		onShow(){
			if (this.isLogin) {
				this.getjiuzhenren()
			}
			
			console.log("12312")
		},
		
		methods: {
			tabsChange(index) {
				this.current = index
			},
			
			//分类跳转
			toCategory(url) {
				// 判断是否登录
				if (!this.isLogin) {
					// 未登录跳转到登录页面
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				if(!url){
					uni.showToast({title: '模板未包含此页面',icon:"none"});
					return;
				}
				uni.navigateTo({
					url:url
				})
			},
			
			// 预约挂号
			takein() {
				// 判断是否登录
				if (!this.isLogin) {
					// 未登录跳转到登录页面
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/register/register'
				})
			},
			// 当日挂号
			takeup(){
				if (!this.isLogin) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/register/register'
				})
			},
			// 门诊缴费
			takeout() {
				if (!this.isLogin) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				uni.navigateTo({
					url: "/pages/address/address?is_choose=true"
				})
			},
			integrals() {
				if (!this.isLogin) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/integrals/integrals'
				})
			},
			packages() {
				uni.navigateTo({
					url: '/pages/packages/index'
				})
			},
			memberCode() {
				if (!this.isLogin) {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/mine/member-code'
				})
			},
			invite() {
				uni.navigateTo({
					url: '/pages/activities/invite'
				})
			},
			getjiuzhenren() {
				
				var data = {
					info: JSON.stringify({
			
						"openid": mm.openid
					})
				};
				
				this.$api.getjiuzhenren(data).then(res => {
			
					console.log('查到的数据:' + JSON.stringify(res));
					this.jiuzhenren = res;
					if(this.jiuzhenren[0].card==null){
						this.flag=false;
						console.log("按钮消失")
					}else{
						this.flag=true;
						if (this.jiuzhenren.length == 1) {
							this.userId = this.jiuzhenren[0].card;
							this.username = this.jiuzhenren[0].name;
							
						} else {
							for (var i = 0; i < this.jiuzhenren.length; i++) {
									
								if (this.jiuzhenren[i].thepatient == 1) {
									this.userId = this.jiuzhenren[i].card;
									this.username = this.jiuzhenren[i].name;
								}else{
									this.userId = this.jiuzhenren[0].card;
									this.username = this.jiuzhenren[0].name;
								}
									
							}
						}
						
						
					}
					
					
			
				}).catch(err => {
					// 登录失败
					uni.hideLoading()
					uni.showToast({
						title: '查找失败',
						icon: 'none'
					});
			
				})
				
			},
		}
	}
</script>

<style lang="scss" scoped>
	/* #ifdef H5 */
	page {
		height: auto;
		min-height: 100%;
	}

	/* #endif */



	.menzhen1 {
		margin-top: 0px;
		display: flex;
		align-items: center;
		justify-content: center;

		.imageadd {
			position: relative;
			margin: 30rpx;
			width: 140rpx;

			.icon {
				width: 70rpx;
				height: 60rpx;
				margin: 20rpx;
			}

			.title {

				text-align: center;
				font-size: 22rpx;
				color: $text-color-base;

			}


		}


	}

	.menzhen2 {
		display: flex;
		align-items: center;
		justify-content: center;

		.imageadd {
			position: relative;
			margin: 30rpx;
			width: 140rpx;

			.icon {
				width: 70rpx;
				height: 60rpx;
				margin: 20rpx;
			}

			.title {
				text-align: center;
				font-size: 22rpx;
				color: $text-color-base;

			}
		}


	}

	.banner {
		position: relative;
		width: 100%;
		height: 600rpx;

		.bg {
			width: 100%;
			height: 300rpx;
		}

		.intro {
			position: absolute;
			top: calc(50rpx + var(--status-bar-height));
			left: 40rpx;
			color: #FFFFFF;
			display: flex;
			flex-direction: column;

			.greet {
				font-size: $font-size-lg;
				margin-bottom: 10rpx;
			}

			.note {
				font-size: $font-size-sm;
			}
		}
	}

	.zhuyuan1 {
		margin-top: 0px;
		display: flex;
		align-items: center;
		justify-content: center;

		.imageadd {
			position: relative;
			margin: 25rpx;
			width: 160rpx;

			.icon {
				width: 70rpx;
				height: 60rpx;
				margin: 10rpx;

			}

			.title {
				text-align: center;
				font-size: 22rpx;
				color: $text-color-base;

			}
		}


	}

	.zhuyuan2 {
		display: flex;
		align-items: center;
		justify-content: center;

		.imageadd {
			position: relative;
			margin: 30rpx;
			width: 140rpx;

			.icon {
				width: 70rpx;
				height: 60rpx;
				margin: 15rpx;
			}

			.title {
				text-align: center;
				font-size: 22rpx;
				color: $text-color-base;

			}
		}


	}

	.content {
		padding: 0 30rpx;
	}

	.entrance {
		position: relative;
		margin-top: -370rpx;
		margin-bottom: 30rpx;
		border-radius: 20rpx;
		background-color: #ffffff;
		box-shadow: $box-shadow;
		padding: 30rpx 0;
		display: flex;
		align-items: center;
		justify-content: center;

		.item {
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			position: relative;

			&:nth-child(1):after {
				content: '';
				position: absolute;
				width: 1rpx;
				background-color: #ddd;
				right: 0;
				height: 100%;
				transform: scaleX(0.5) scaleY(0.8);
			}

			&:nth-child(2):after {
				content: '';
				position: absolute;
				width: 1rpx;
				background-color: #ddd;
				right: 0;
				height: 100%;
				transform: scaleX(0.5) scaleY(0.8);
			}

			.icon {
				width: 84rpx;
				height: 84rpx;
				margin: 20rpx;
			}

			.title {
				font-size: 30rpx;
				color: $text-color-base;
				font-weight: 600;
			}
		}
	}

	.info {
		position: relative;
		margin-bottom: 30rpx;
		border-radius: 10rpx;
		background-color: #ffffff;
		box-shadow: $box-shadow;

		display: flex;
		align-items: center;
		justify-content: center;

		.integral_section {
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: center;

			.top {
				display: flex;
				align-items: center;

				.title {
					color: $text-color-base;
					font-size: $font-size-base;
					margin-right: 10rpx;
				}

				.value {
					font-size: 44rpx;
					font-weight: bold;
				}
			}

			.bottom {
				font-size: $font-size-sm;
				color: $text-color-assist;
				display: flex;
				align-items: center;

				button {
					width: 250rpx;
					margin-left: 50rpx;
					background-color: transparent;
					border-style: none;
					font-size: 28rpx;
					color: #3ECEB6;
				}

			}
		}

		.qrcode_section {
			color: $color-primary;
			display: flex;

			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-size: $font-size-sm;

			image {
				width: 400rpx;
				height: 160rpx;

			}

		}
	}

	.navigators {
		width: 100%;
		margin-bottom: 20rpx;
		border-radius: 10rpx;
		background-color: #ffffff;
		box-shadow: $box-shadow;
		padding: 20rpx;
		display: flex;
		align-items: stretch;

		.left {
			width: 340rpx;
			margin-right: 20rpx;
			display: flex;
			padding: 0 20rpx;
			flex-direction: column;
			font-size: $font-size-sm;
			color: $text-color-base;
			background-color: #F2F2E6;

			.grid {
				height: 50%;
				display: flex;
			}
		}

		.right {
			width: 290rpx;
			display: flex;
			flex-direction: column;

			.tea-activity,
			.member-gifts {
				width: 100%;
				display: flex;
				padding: 20rpx;
				font-size: $font-size-sm;
				color: $text-color-base;
				align-items: center;
				position: relative;
			}

			.tea-activity {
				background-color: #FDF3F2;
				margin-bottom: 20rpx;
			}

			.member-gifts {
				background-color: #FCF6D4;
			}

			.right-img {
				flex: 1;
				position: relative;
				margin-left: 20rpx;
				margin-right: -20rpx;
				margin-bottom: -20rpx;
				display: flex;
				align-items: flex-end;

				image {
					width: 100%;
				}
			}
		}

		.mark-img {
			width: 30rpx;
			height: 30rpx;
			margin-right: 10rpx;
		}

		.yzclh-img {
			height: 122.96rpx;
			width: 214.86rpx;
		}
	}

	.category-list {
		width: 92%;
		margin: 0 4%;
		padding: 0 0 30upx 0;
		// border-bottom: solid 2upx #f6f6f6;
		display: flex;
		// justify-content: space-between;
		flex-wrap: wrap;

		.category {
			width: 25%;
			margin-top: 50upx;
			display: flex;
			flex-wrap: wrap;

			.img {
				width: 100%;
				display: flex;
				justify-content: center;

				image {
					width: 9vw;
					height: 9vw;
				}
			}

			.text {
				margin-top: 16upx;
				width: 100%;
				display: flex;
				justify-content: center;
				font-size: 24upx;
				color: #3c3c3c;
			}
		}
	}


	.member-news {
		width: 100%;
		margin-bottom: 30rpx;

		.header {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx 0;

			.title {
				font-size: $font-size-lg;
				font-weight: bold;
			}

			.iconfont {
				font-size: 52rpx;
				color: $text-color-assist;
			}
		}


		.list {
			width: 100%;
			display: flex;
			flex-direction: column;

			.item {
				width: 100%;
				height: 240rpx;
				position: relative;

				image {
					width: 100%;
					height: 100%;
					border-radius: 8rpx;
				}

				.title {
					position: relative;
					font-size: 32rpx;
					font-weight: 500;
					width: 100%;
					top: -70rpx;
					left: 16rpx;
					color: #ffffff;
				}
			}
		}
	}
</style>
